package com.javaee.xiangyang.mapper;

import com.javaee.xiangyang.dto.GoodsComment;
import com.javaee.xiangyang.dto.UserComment;
import com.javaee.xiangyang.entity.Comment;
import com.javaee.xiangyang.entity.Goods;
import com.javaee.xiangyang.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;


@Mapper
@Repository
public interface CommentMapper {

    /**
     * 新增评论
     */
//    @Insert("insert into comment values(#{commentId}, #{commentContent}, #{commentTime}, #{commentState}, #{commentUserAccount}, #{commentGoodsId})")
    void addComment(Comment comment);

    /**
     * 查看所有评论
     */
//    @Select("select * from comment")
    List<Comment> findAllComment();

    /**
     * 查看对应用户生成的评论
     */
//    @Select("select * from comment where commentUserAccount = #{commentUserAccount}")
    List<Comment> findAllCommentByUserAccount(User user);

    /**
     * 查看对应商品拥有的评论
     */
//    @Select("select * from comment where commentGoodsId = #{commentGoodsId}")
    List<Comment> findAllCommentByGoodsId(Goods goods);

    /**
     * 根据评论ID查找评论
     */
//    @Select("select * from comment where commentId = #{commentId}")
    Comment findCommentByCommentId(Comment comment);

    /**
     * 更改评论当前状态
     */
//    @Update("update comment set commentState = #{CommentState} where commentId = #{commentId}")
    void updateStateByCommentId(Comment comment);

    /**
     * 删除当前评论
     */
//    @Delete("delete from comment where commentId = #{commentId}")
    void deleteCommentByCommentId(Comment comment);

    /*=========================================封装类DTO查询==============================================*/

    /**
     * 封装类查询   以商品Id查询商品所有评论
     */
//    @Select("select user.userName,user.userHead,commentContent,commentTime,commentId,commentState,userAccount from user,comment where commentGoodsId = #{commentGoodsId} and commentUserAccount = userAccount")
    List<GoodsComment> findAllGoodsCommentByGoodsId(Goods goods);

    /**
     * 封装类查询   以用户Id查询用户生成的评论
     */
//    @Select("select goodsId,GoodsName,commentId,commentContent,commentTime,commentState from goods,comment where commentGoodsId = #{commentGoodsId} and commentGoodsId = goodsId")
    List<UserComment> findAllUserCommentByUserId(User user);

}
